<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css" type="text/css">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" type="text/css">
    <link rel="stylesheet" href="./resources/prism/prism.css" type="text/css">
    <link rel="stylesheet" href="../css/ol.css" type="text/css">
    <link rel="stylesheet" href="./resources/layout.css" type="text/css">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.4.4/proj4.js"></script>
    
    <script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=fetch,requestAnimationFrame,Element.prototype.classList,URL"></script>
    <script src="./resources/zeroclipboard/ZeroClipboard.min.js"></script>
    <title>Raster Reprojection</title>
  </head>
  <body>

    <header class="navbar" role="navigation">
      <div class="container">
        <div class="display-table pull-left" id="navbar-logo-container">
          <a class="navbar-brand" href="./"><img src="./resources/logo-70x70.png">&nbsp;OpenLayers Examples</a>
        </div>
        <!-- menu items that get hidden below 768px width -->
        <nav class='collapse navbar-collapse navbar-responsive-collapse'>
          <ul class="nav navbar-nav pull-right">
            <li><a href="../doc">Docs</a></li>
            <li><a class="active" href="index.html">Examples</a></li>
            <li><a href="../apidoc">API</a></li>
            <li><a href="https://github.com/openlayers/openlayers">Code</a></li>
          </ul>
        </nav>
      </div>
    </header>

    <div class="container-fluid">

      <div id="latest-check" class="alert alert-warning alert-dismissible" role="alert" style="display:none">
        <button id="latest-dismiss" type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        This example uses OpenLayers v<span>4.6.5</span>. The <a id="latest-link" href="#" class="alert-link">latest</a> is v<span id="latest-version"></span>.
      </div>

      <div class="row-fluid">
        <div class="span12">
          <h4 id="title">Raster Reprojection</h4>
          <div id="map" class="map"></div>
<form class="form-inline">
  <div class="col-md-3">
    <label>Base map:</label>
    <select id="base-layer">
      <option value="osm">OSM (EPSG:3857)</option>
      <option value="wms4326">WMS (EPSG:4326)</option>
    </select>
  </div>
  <div class="col-md-4">
    <label>Overlay map:</label>
    <select id="overlay-layer">
      <option value="bng">British National Grid (EPSG:27700)</option>
      <option value="wms21781">Swisstopo WMS (EPSG:21781)</option>
      <option value="wmts3413">NASA Arctic WMTS (EPSG:3413)</option>
      <option value="grandcanyon">Grand Canyon HiDPI (EPSG:3857)</option>
      <option value="states">United States (EPSG:3857)</option>
    </select>
  </div>
  <div class="col-md-5">
    <label>View projection:</label>
    <select id="view-projection">
      <option value="EPSG:3857">Spherical Mercator (EPSG:3857)</option>
      <option value="EPSG:4326">WGS 84 (EPSG:4326)</option>
      <option value="ESRI:54009">Mollweide (ESRI:54009)</option>
      <option value="EPSG:27700">British National Grid (EPSG:27700)</option>
      <option value="EPSG:23032">ED50 / UTM zone 32N (EPSG:23032)</option>
      <option value="EPSG:2163">US National Atlas Equal Area (EPSG:2163)</option>
      <option value="EPSG:3413">NSIDC Polar Stereographic North (EPSG:3413)</option>
      <option value="EPSG:5479">RSRGD2000 / MSLC2000 (EPSG:5479)</option>
    </select>
  </div>
  <label>
    Render reprojection edges
    <input type="checkbox" id="render-edges">
  </label>
</form>

        </div>
      </div>

      <div class="row-fluid">
        <div class="span12">
          <p id="shortdesc">Demonstrates client-side raster reprojection between various projections.</p>
          <div id="docs"><p>This example shows client-side raster reprojection between various projections.</p>
</div>
          <div id="api-links">Related API documentation: <ul class="inline"><li><a href="../apidoc/ol.Map.html" title="API documentation for ol.Map">ol.Map</a></li>,<li><a href="../apidoc/ol.View.html" title="API documentation for ol.View">ol.View</a></li>,<li><a href="../apidoc/ol.extent.html" title="API documentation for ol.extent">ol.extent</a></li>,<li><a href="../apidoc/ol.format.WMTSCapabilities.html" title="API documentation for ol.format.WMTSCapabilities">ol.format.WMTSCapabilities</a></li>,<li><a href="../apidoc/ol.layer.Tile.html" title="API documentation for ol.layer.Tile">ol.layer.Tile</a></li>,<li><a href="../apidoc/ol.proj.html" title="API documentation for ol.proj">ol.proj</a></li>,<li><a href="../apidoc/ol.source.OSM.html" title="API documentation for ol.source.OSM">ol.source.OSM</a></li>,<li><a href="../apidoc/ol.source.TileImage.html" title="API documentation for ol.source.TileImage">ol.source.TileImage</a></li>,<li><a href="../apidoc/ol.source.TileWMS.html" title="API documentation for ol.source.TileWMS">ol.source.TileWMS</a></li>,<li><a href="../apidoc/ol.source.WMTS.html" title="API documentation for ol.source.WMTS">ol.source.WMTS</a></li>,<li><a href="../apidoc/ol.source.XYZ.html" title="API documentation for ol.source.XYZ">ol.source.XYZ</a></li>,<li><a href="../apidoc/ol.tilegrid.TileGrid.html" title="API documentation for ol.tilegrid.TileGrid">ol.tilegrid.TileGrid</a></li></ul></div>
        </div>
      </div>

      <div class="row-fluid">
        <div id="source-controls">
          <a id="copy-button"><i class="fa fa-clipboard"></i> Copy</a>
          <a id="codepen-button"><i class="fa fa-codepen"></i> Edit</a>
        </div>
        <form method="POST" id="codepen-form" target="_blank" action="https://codepen.io/pen/define/">
          <textarea class="hidden" name="title">Raster Reprojection</textarea>
          <textarea class="hidden" name="description">Demonstrates client-side raster reprojection between various projections.</textarea>
          <textarea class="hidden" name="js">proj4.defs(&#x27;EPSG:27700&#x27;, &#x27;+proj&#x3D;tmerc +lat_0&#x3D;49 +lon_0&#x3D;-2 +k&#x3D;0.9996012717 &#x27; +
    &#x27;+x_0&#x3D;400000 +y_0&#x3D;-100000 +ellps&#x3D;airy &#x27; +
    &#x27;+towgs84&#x3D;446.448,-125.157,542.06,0.15,0.247,0.842,-20.489 &#x27; +
    &#x27;+units&#x3D;m +no_defs&#x27;);
var proj27700 &#x3D; ol.proj.get(&#x27;EPSG:27700&#x27;);
proj27700.setExtent([0, 0, 700000, 1300000]);

proj4.defs(&#x27;EPSG:23032&#x27;, &#x27;+proj&#x3D;utm +zone&#x3D;32 +ellps&#x3D;intl &#x27; +
    &#x27;+towgs84&#x3D;-87,-98,-121,0,0,0,0 +units&#x3D;m +no_defs&#x27;);
var proj23032 &#x3D; ol.proj.get(&#x27;EPSG:23032&#x27;);
proj23032.setExtent([-1206118.71, 4021309.92, 1295389.00, 8051813.28]);

proj4.defs(&#x27;EPSG:5479&#x27;, &#x27;+proj&#x3D;lcc +lat_1&#x3D;-76.66666666666667 +lat_2&#x3D;&#x27; +
    &#x27;-79.33333333333333 +lat_0&#x3D;-78 +lon_0&#x3D;163 +x_0&#x3D;7000000 +y_0&#x3D;5000000 &#x27; +
    &#x27;+ellps&#x3D;GRS80 +towgs84&#x3D;0,0,0,0,0,0,0 +units&#x3D;m +no_defs&#x27;);
var proj5479 &#x3D; ol.proj.get(&#x27;EPSG:5479&#x27;);
proj5479.setExtent([6825737.53, 4189159.80, 9633741.96, 5782472.71]);

proj4.defs(&#x27;EPSG:21781&#x27;, &#x27;+proj&#x3D;somerc +lat_0&#x3D;46.95240555555556 &#x27; +
    &#x27;+lon_0&#x3D;7.439583333333333 +k_0&#x3D;1 +x_0&#x3D;600000 +y_0&#x3D;200000 +ellps&#x3D;bessel &#x27; +
    &#x27;+towgs84&#x3D;674.4,15.1,405.3,0,0,0,0 +units&#x3D;m +no_defs&#x27;);
var proj21781 &#x3D; ol.proj.get(&#x27;EPSG:21781&#x27;);
proj21781.setExtent([485071.54, 75346.36, 828515.78, 299941.84]);

proj4.defs(&#x27;EPSG:3413&#x27;, &#x27;+proj&#x3D;stere +lat_0&#x3D;90 +lat_ts&#x3D;70 +lon_0&#x3D;-45 +k&#x3D;1 &#x27; +
    &#x27;+x_0&#x3D;0 +y_0&#x3D;0 +datum&#x3D;WGS84 +units&#x3D;m +no_defs&#x27;);
var proj3413 &#x3D; ol.proj.get(&#x27;EPSG:3413&#x27;);
proj3413.setExtent([-4194304, -4194304, 4194304, 4194304]);

proj4.defs(&#x27;EPSG:2163&#x27;, &#x27;+proj&#x3D;laea +lat_0&#x3D;45 +lon_0&#x3D;-100 +x_0&#x3D;0 +y_0&#x3D;0 &#x27; +
    &#x27;+a&#x3D;6370997 +b&#x3D;6370997 +units&#x3D;m +no_defs&#x27;);
var proj2163 &#x3D; ol.proj.get(&#x27;EPSG:2163&#x27;);
proj2163.setExtent([-8040784.5135, -2577524.9210, 3668901.4484, 4785105.1096]);

proj4.defs(&#x27;ESRI:54009&#x27;, &#x27;+proj&#x3D;moll +lon_0&#x3D;0 +x_0&#x3D;0 +y_0&#x3D;0 +datum&#x3D;WGS84 &#x27; +
    &#x27;+units&#x3D;m +no_defs&#x27;);
var proj54009 &#x3D; ol.proj.get(&#x27;ESRI:54009&#x27;);
proj54009.setExtent([-18e6, -9e6, 18e6, 9e6]);


var layers &#x3D; {};

layers[&#x27;bng&#x27;] &#x3D; new ol.layer.Tile({
  source: new ol.source.XYZ({
    projection: &#x27;EPSG:27700&#x27;,
    url: &#x27;https://tileserver.maptiler.com/miniscale/{z}/{x}/{y}.png&#x27;,
    crossOrigin: &#x27;&#x27;,
    maxZoom: 6
  })
});

layers[&#x27;osm&#x27;] &#x3D; new ol.layer.Tile({
  source: new ol.source.OSM()
});

layers[&#x27;wms4326&#x27;] &#x3D; new ol.layer.Tile({
  source: new ol.source.TileWMS({
    url: &#x27;https://ahocevar.com/geoserver/wms&#x27;,
    crossOrigin: &#x27;&#x27;,
    params: {
      &#x27;LAYERS&#x27;: &#x27;ne:NE1_HR_LC_SR_W_DR&#x27;,
      &#x27;TILED&#x27;: true
    },
    projection: &#x27;EPSG:4326&#x27;
  })
});

layers[&#x27;wms21781&#x27;] &#x3D; new ol.layer.Tile({
  source: new ol.source.TileWMS({
    attributions: &#x27;© &lt;a href&#x3D;&quot;http://www.geo.admin.ch/internet/geoportal/&#x27; +
      &#x27;en/home.html&quot;&gt;Pixelmap 1:1000000 / geo.admin.ch&lt;/a&gt;&#x27;,
    crossOrigin: &#x27;anonymous&#x27;,
    params: {
      &#x27;LAYERS&#x27;: &#x27;ch.swisstopo.pixelkarte-farbe-pk1000.noscale&#x27;,
      &#x27;FORMAT&#x27;: &#x27;image/jpeg&#x27;
    },
    url: &#x27;https://wms.geo.admin.ch/&#x27;,
    projection: &#x27;EPSG:21781&#x27;
  })
});

var parser &#x3D; new ol.format.WMTSCapabilities();
var url &#x3D; &#x27;https://map1.vis.earthdata.nasa.gov/wmts-arctic/&#x27; +
    &#x27;wmts.cgi?SERVICE&#x3D;WMTS&amp;request&#x3D;GetCapabilities&#x27;;
fetch(url).then(function(response) {
  return response.text();
}).then(function(text) {
  var result &#x3D; parser.read(text);
  var options &#x3D; ol.source.WMTS.optionsFromCapabilities(result, {
    layer: &#x27;OSM_Land_Mask&#x27;,
    matrixSet: &#x27;EPSG3413_250m&#x27;
  });
  options.crossOrigin &#x3D; &#x27;&#x27;;
  options.projection &#x3D; &#x27;EPSG:3413&#x27;;
  options.wrapX &#x3D; false;
  layers[&#x27;wmts3413&#x27;] &#x3D; new ol.layer.Tile({
    source: new ol.source.WMTS(/** @type {!olx.source.WMTSOptions} */ (options))
  });
});

layers[&#x27;grandcanyon&#x27;] &#x3D; new ol.layer.Tile({
  source: new ol.source.XYZ({
    url: &#x27;https://tileserver.maptiler.com/grandcanyon@2x/{z}/{x}/{y}.png&#x27;,
    crossOrigin: &#x27;&#x27;,
    tilePixelRatio: 2,
    maxZoom: 15,
    attributions: &#x27;Tiles © USGS, rendered with &#x27; +
      &#x27;&lt;a href&#x3D;&quot;http://www.maptiler.com/&quot;&gt;MapTiler&lt;/a&gt;&#x27;
  })
});

var startResolution &#x3D;
    ol.extent.getWidth(ol.proj.get(&#x27;EPSG:3857&#x27;).getExtent()) / 256;
var resolutions &#x3D; new Array(22);
for (var i &#x3D; 0, ii &#x3D; resolutions.length; i &lt; ii; ++i) {
  resolutions[i] &#x3D; startResolution / Math.pow(2, i);
}

layers[&#x27;states&#x27;] &#x3D; new ol.layer.Tile({
  source: new ol.source.TileWMS({
    url: &#x27;https://ahocevar.com/geoserver/wms&#x27;,
    crossOrigin: &#x27;&#x27;,
    params: {&#x27;LAYERS&#x27;: &#x27;topp:states&#x27;},
    serverType: &#x27;geoserver&#x27;,
    tileGrid: new ol.tilegrid.TileGrid({
      extent: [-13884991, 2870341, -7455066, 6338219],
      resolutions: resolutions,
      tileSize: [512, 256]
    }),
    projection: &#x27;EPSG:3857&#x27;
  })
});


var map &#x3D; new ol.Map({
  layers: [
    layers[&#x27;osm&#x27;],
    layers[&#x27;bng&#x27;]
  ],
  target: &#x27;map&#x27;,
  view: new ol.View({
    projection: &#x27;EPSG:3857&#x27;,
    center: [0, 0],
    zoom: 2
  })
});


var baseLayerSelect &#x3D; document.getElementById(&#x27;base-layer&#x27;);
var overlayLayerSelect &#x3D; document.getElementById(&#x27;overlay-layer&#x27;);
var viewProjSelect &#x3D; document.getElementById(&#x27;view-projection&#x27;);
var renderEdgesCheckbox &#x3D; document.getElementById(&#x27;render-edges&#x27;);
var renderEdges &#x3D; false;

function updateViewProjection() {
  var newProj &#x3D; ol.proj.get(viewProjSelect.value);
  var newProjExtent &#x3D; newProj.getExtent();
  var newView &#x3D; new ol.View({
    projection: newProj,
    center: ol.extent.getCenter(newProjExtent || [0, 0, 0, 0]),
    zoom: 0,
    extent: newProjExtent || undefined
  });
  map.setView(newView);

  // Example how to prevent double occurrence of map by limiting layer extent
  if (newProj &#x3D;&#x3D; ol.proj.get(&#x27;EPSG:3857&#x27;)) {
    layers[&#x27;bng&#x27;].setExtent([-1057216, 6405988, 404315, 8759696]);
  } else {
    layers[&#x27;bng&#x27;].setExtent(undefined);
  }
}


/**
 * Handle change event.
 */
viewProjSelect.onchange &#x3D; function() {
  updateViewProjection();
};

updateViewProjection();

var updateRenderEdgesOnLayer &#x3D; function(layer) {
  if (layer instanceof ol.layer.Tile) {
    var source &#x3D; layer.getSource();
    if (source instanceof ol.source.TileImage) {
      source.setRenderReprojectionEdges(renderEdges);
    }
  }
};


/**
 * Handle change event.
 */
baseLayerSelect.onchange &#x3D; function() {
  var layer &#x3D; layers[baseLayerSelect.value];
  if (layer) {
    layer.setOpacity(1);
    updateRenderEdgesOnLayer(layer);
    map.getLayers().setAt(0, layer);
  }
};


/**
 * Handle change event.
 */
overlayLayerSelect.onchange &#x3D; function() {
  var layer &#x3D; layers[overlayLayerSelect.value];
  if (layer) {
    layer.setOpacity(0.7);
    updateRenderEdgesOnLayer(layer);
    map.getLayers().setAt(1, layer);
  }
};


/**
 * Handle change event.
 */
renderEdgesCheckbox.onchange &#x3D; function() {
  renderEdges &#x3D; renderEdgesCheckbox.checked;
  map.getLayers().forEach(function(layer) {
    updateRenderEdgesOnLayer(layer);
  });
};
</textarea>
          <textarea class="hidden" name="css"></textarea>
          <textarea class="hidden" name="html">&lt;div id&#x3D;&quot;map&quot; class&#x3D;&quot;map&quot;&gt;&lt;/div&gt;
&lt;form class&#x3D;&quot;form-inline&quot;&gt;
  &lt;div class&#x3D;&quot;col-md-3&quot;&gt;
    &lt;label&gt;Base map:&lt;/label&gt;
    &lt;select id&#x3D;&quot;base-layer&quot;&gt;
      &lt;option value&#x3D;&quot;osm&quot;&gt;OSM (EPSG:3857)&lt;/option&gt;
      &lt;option value&#x3D;&quot;wms4326&quot;&gt;WMS (EPSG:4326)&lt;/option&gt;
    &lt;/select&gt;
  &lt;/div&gt;
  &lt;div class&#x3D;&quot;col-md-4&quot;&gt;
    &lt;label&gt;Overlay map:&lt;/label&gt;
    &lt;select id&#x3D;&quot;overlay-layer&quot;&gt;
      &lt;option value&#x3D;&quot;bng&quot;&gt;British National Grid (EPSG:27700)&lt;/option&gt;
      &lt;option value&#x3D;&quot;wms21781&quot;&gt;Swisstopo WMS (EPSG:21781)&lt;/option&gt;
      &lt;option value&#x3D;&quot;wmts3413&quot;&gt;NASA Arctic WMTS (EPSG:3413)&lt;/option&gt;
      &lt;option value&#x3D;&quot;grandcanyon&quot;&gt;Grand Canyon HiDPI (EPSG:3857)&lt;/option&gt;
      &lt;option value&#x3D;&quot;states&quot;&gt;United States (EPSG:3857)&lt;/option&gt;
    &lt;/select&gt;
  &lt;/div&gt;
  &lt;div class&#x3D;&quot;col-md-5&quot;&gt;
    &lt;label&gt;View projection:&lt;/label&gt;
    &lt;select id&#x3D;&quot;view-projection&quot;&gt;
      &lt;option value&#x3D;&quot;EPSG:3857&quot;&gt;Spherical Mercator (EPSG:3857)&lt;/option&gt;
      &lt;option value&#x3D;&quot;EPSG:4326&quot;&gt;WGS 84 (EPSG:4326)&lt;/option&gt;
      &lt;option value&#x3D;&quot;ESRI:54009&quot;&gt;Mollweide (ESRI:54009)&lt;/option&gt;
      &lt;option value&#x3D;&quot;EPSG:27700&quot;&gt;British National Grid (EPSG:27700)&lt;/option&gt;
      &lt;option value&#x3D;&quot;EPSG:23032&quot;&gt;ED50 / UTM zone 32N (EPSG:23032)&lt;/option&gt;
      &lt;option value&#x3D;&quot;EPSG:2163&quot;&gt;US National Atlas Equal Area (EPSG:2163)&lt;/option&gt;
      &lt;option value&#x3D;&quot;EPSG:3413&quot;&gt;NSIDC Polar Stereographic North (EPSG:3413)&lt;/option&gt;
      &lt;option value&#x3D;&quot;EPSG:5479&quot;&gt;RSRGD2000 / MSLC2000 (EPSG:5479)&lt;/option&gt;
    &lt;/select&gt;
  &lt;/div&gt;
  &lt;label&gt;
    Render reprojection edges
    &lt;input type&#x3D;&quot;checkbox&quot; id&#x3D;&quot;render-edges&quot;&gt;
  &lt;/label&gt;
&lt;/form&gt;
</textarea>
          <input type="hidden" name="resources" value="https://openlayers.org/en/v4.6.5/css/ol.css,https://openlayers.org/en/v4.6.5/build/ol.js,https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.4.4/proj4.js">
          <input type="hidden" name="data">
        </form>
        <pre><code id="example-source" class="language-markup">&lt;!DOCTYPE html&gt;
&lt;html&gt;
  &lt;head&gt;
    &lt;title&gt;Raster Reprojection&lt;/title&gt;
    &lt;link rel="stylesheet" href="https://openlayers.org/en/v4.6.5/css/ol.css" type="text/css"&gt;
    &lt;!-- The line below is only needed for old environments like Internet Explorer and Android 4.x --&gt;
    &lt;script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL"&gt;&lt;/script&gt;
    &lt;script src="https://openlayers.org/en/v4.6.5/build/ol.js"&gt;&lt;/script&gt;
    &lt;script src&#x3D;&quot;https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.4.4/proj4.js&quot;&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;div id&#x3D;&quot;map&quot; class&#x3D;&quot;map&quot;&gt;&lt;/div&gt;
    &lt;form class&#x3D;&quot;form-inline&quot;&gt;
      &lt;div class&#x3D;&quot;col-md-3&quot;&gt;
        &lt;label&gt;Base map:&lt;/label&gt;
        &lt;select id&#x3D;&quot;base-layer&quot;&gt;
          &lt;option value&#x3D;&quot;osm&quot;&gt;OSM (EPSG:3857)&lt;/option&gt;
          &lt;option value&#x3D;&quot;wms4326&quot;&gt;WMS (EPSG:4326)&lt;/option&gt;
        &lt;/select&gt;
      &lt;/div&gt;
      &lt;div class&#x3D;&quot;col-md-4&quot;&gt;
        &lt;label&gt;Overlay map:&lt;/label&gt;
        &lt;select id&#x3D;&quot;overlay-layer&quot;&gt;
          &lt;option value&#x3D;&quot;bng&quot;&gt;British National Grid (EPSG:27700)&lt;/option&gt;
          &lt;option value&#x3D;&quot;wms21781&quot;&gt;Swisstopo WMS (EPSG:21781)&lt;/option&gt;
          &lt;option value&#x3D;&quot;wmts3413&quot;&gt;NASA Arctic WMTS (EPSG:3413)&lt;/option&gt;
          &lt;option value&#x3D;&quot;grandcanyon&quot;&gt;Grand Canyon HiDPI (EPSG:3857)&lt;/option&gt;
          &lt;option value&#x3D;&quot;states&quot;&gt;United States (EPSG:3857)&lt;/option&gt;
        &lt;/select&gt;
      &lt;/div&gt;
      &lt;div class&#x3D;&quot;col-md-5&quot;&gt;
        &lt;label&gt;View projection:&lt;/label&gt;
        &lt;select id&#x3D;&quot;view-projection&quot;&gt;
          &lt;option value&#x3D;&quot;EPSG:3857&quot;&gt;Spherical Mercator (EPSG:3857)&lt;/option&gt;
          &lt;option value&#x3D;&quot;EPSG:4326&quot;&gt;WGS 84 (EPSG:4326)&lt;/option&gt;
          &lt;option value&#x3D;&quot;ESRI:54009&quot;&gt;Mollweide (ESRI:54009)&lt;/option&gt;
          &lt;option value&#x3D;&quot;EPSG:27700&quot;&gt;British National Grid (EPSG:27700)&lt;/option&gt;
          &lt;option value&#x3D;&quot;EPSG:23032&quot;&gt;ED50 / UTM zone 32N (EPSG:23032)&lt;/option&gt;
          &lt;option value&#x3D;&quot;EPSG:2163&quot;&gt;US National Atlas Equal Area (EPSG:2163)&lt;/option&gt;
          &lt;option value&#x3D;&quot;EPSG:3413&quot;&gt;NSIDC Polar Stereographic North (EPSG:3413)&lt;/option&gt;
          &lt;option value&#x3D;&quot;EPSG:5479&quot;&gt;RSRGD2000 / MSLC2000 (EPSG:5479)&lt;/option&gt;
        &lt;/select&gt;
      &lt;/div&gt;
      &lt;label&gt;
        Render reprojection edges
        &lt;input type&#x3D;&quot;checkbox&quot; id&#x3D;&quot;render-edges&quot;&gt;
      &lt;/label&gt;
    &lt;/form&gt;
    &lt;script&gt;
      proj4.defs(&#x27;EPSG:27700&#x27;, &#x27;+proj&#x3D;tmerc +lat_0&#x3D;49 +lon_0&#x3D;-2 +k&#x3D;0.9996012717 &#x27; +
          &#x27;+x_0&#x3D;400000 +y_0&#x3D;-100000 +ellps&#x3D;airy &#x27; +
          &#x27;+towgs84&#x3D;446.448,-125.157,542.06,0.15,0.247,0.842,-20.489 &#x27; +
          &#x27;+units&#x3D;m +no_defs&#x27;);
      var proj27700 &#x3D; ol.proj.get(&#x27;EPSG:27700&#x27;);
      proj27700.setExtent([0, 0, 700000, 1300000]);

      proj4.defs(&#x27;EPSG:23032&#x27;, &#x27;+proj&#x3D;utm +zone&#x3D;32 +ellps&#x3D;intl &#x27; +
          &#x27;+towgs84&#x3D;-87,-98,-121,0,0,0,0 +units&#x3D;m +no_defs&#x27;);
      var proj23032 &#x3D; ol.proj.get(&#x27;EPSG:23032&#x27;);
      proj23032.setExtent([-1206118.71, 4021309.92, 1295389.00, 8051813.28]);

      proj4.defs(&#x27;EPSG:5479&#x27;, &#x27;+proj&#x3D;lcc +lat_1&#x3D;-76.66666666666667 +lat_2&#x3D;&#x27; +
          &#x27;-79.33333333333333 +lat_0&#x3D;-78 +lon_0&#x3D;163 +x_0&#x3D;7000000 +y_0&#x3D;5000000 &#x27; +
          &#x27;+ellps&#x3D;GRS80 +towgs84&#x3D;0,0,0,0,0,0,0 +units&#x3D;m +no_defs&#x27;);
      var proj5479 &#x3D; ol.proj.get(&#x27;EPSG:5479&#x27;);
      proj5479.setExtent([6825737.53, 4189159.80, 9633741.96, 5782472.71]);

      proj4.defs(&#x27;EPSG:21781&#x27;, &#x27;+proj&#x3D;somerc +lat_0&#x3D;46.95240555555556 &#x27; +
          &#x27;+lon_0&#x3D;7.439583333333333 +k_0&#x3D;1 +x_0&#x3D;600000 +y_0&#x3D;200000 +ellps&#x3D;bessel &#x27; +
          &#x27;+towgs84&#x3D;674.4,15.1,405.3,0,0,0,0 +units&#x3D;m +no_defs&#x27;);
      var proj21781 &#x3D; ol.proj.get(&#x27;EPSG:21781&#x27;);
      proj21781.setExtent([485071.54, 75346.36, 828515.78, 299941.84]);

      proj4.defs(&#x27;EPSG:3413&#x27;, &#x27;+proj&#x3D;stere +lat_0&#x3D;90 +lat_ts&#x3D;70 +lon_0&#x3D;-45 +k&#x3D;1 &#x27; +
          &#x27;+x_0&#x3D;0 +y_0&#x3D;0 +datum&#x3D;WGS84 +units&#x3D;m +no_defs&#x27;);
      var proj3413 &#x3D; ol.proj.get(&#x27;EPSG:3413&#x27;);
      proj3413.setExtent([-4194304, -4194304, 4194304, 4194304]);

      proj4.defs(&#x27;EPSG:2163&#x27;, &#x27;+proj&#x3D;laea +lat_0&#x3D;45 +lon_0&#x3D;-100 +x_0&#x3D;0 +y_0&#x3D;0 &#x27; +
          &#x27;+a&#x3D;6370997 +b&#x3D;6370997 +units&#x3D;m +no_defs&#x27;);
      var proj2163 &#x3D; ol.proj.get(&#x27;EPSG:2163&#x27;);
      proj2163.setExtent([-8040784.5135, -2577524.9210, 3668901.4484, 4785105.1096]);

      proj4.defs(&#x27;ESRI:54009&#x27;, &#x27;+proj&#x3D;moll +lon_0&#x3D;0 +x_0&#x3D;0 +y_0&#x3D;0 +datum&#x3D;WGS84 &#x27; +
          &#x27;+units&#x3D;m +no_defs&#x27;);
      var proj54009 &#x3D; ol.proj.get(&#x27;ESRI:54009&#x27;);
      proj54009.setExtent([-18e6, -9e6, 18e6, 9e6]);


      var layers &#x3D; {};

      layers[&#x27;bng&#x27;] &#x3D; new ol.layer.Tile({
        source: new ol.source.XYZ({
          projection: &#x27;EPSG:27700&#x27;,
          url: &#x27;https://tileserver.maptiler.com/miniscale/{z}/{x}/{y}.png&#x27;,
          crossOrigin: &#x27;&#x27;,
          maxZoom: 6
        })
      });

      layers[&#x27;osm&#x27;] &#x3D; new ol.layer.Tile({
        source: new ol.source.OSM()
      });

      layers[&#x27;wms4326&#x27;] &#x3D; new ol.layer.Tile({
        source: new ol.source.TileWMS({
          url: &#x27;https://ahocevar.com/geoserver/wms&#x27;,
          crossOrigin: &#x27;&#x27;,
          params: {
            &#x27;LAYERS&#x27;: &#x27;ne:NE1_HR_LC_SR_W_DR&#x27;,
            &#x27;TILED&#x27;: true
          },
          projection: &#x27;EPSG:4326&#x27;
        })
      });

      layers[&#x27;wms21781&#x27;] &#x3D; new ol.layer.Tile({
        source: new ol.source.TileWMS({
          attributions: &#x27;© &lt;a href&#x3D;&quot;http://www.geo.admin.ch/internet/geoportal/&#x27; +
            &#x27;en/home.html&quot;&gt;Pixelmap 1:1000000 / geo.admin.ch&lt;/a&gt;&#x27;,
          crossOrigin: &#x27;anonymous&#x27;,
          params: {
            &#x27;LAYERS&#x27;: &#x27;ch.swisstopo.pixelkarte-farbe-pk1000.noscale&#x27;,
            &#x27;FORMAT&#x27;: &#x27;image/jpeg&#x27;
          },
          url: &#x27;https://wms.geo.admin.ch/&#x27;,
          projection: &#x27;EPSG:21781&#x27;
        })
      });

      var parser &#x3D; new ol.format.WMTSCapabilities();
      var url &#x3D; &#x27;https://map1.vis.earthdata.nasa.gov/wmts-arctic/&#x27; +
          &#x27;wmts.cgi?SERVICE&#x3D;WMTS&amp;request&#x3D;GetCapabilities&#x27;;
      fetch(url).then(function(response) {
        return response.text();
      }).then(function(text) {
        var result &#x3D; parser.read(text);
        var options &#x3D; ol.source.WMTS.optionsFromCapabilities(result, {
          layer: &#x27;OSM_Land_Mask&#x27;,
          matrixSet: &#x27;EPSG3413_250m&#x27;
        });
        options.crossOrigin &#x3D; &#x27;&#x27;;
        options.projection &#x3D; &#x27;EPSG:3413&#x27;;
        options.wrapX &#x3D; false;
        layers[&#x27;wmts3413&#x27;] &#x3D; new ol.layer.Tile({
          source: new ol.source.WMTS(/** @type {!olx.source.WMTSOptions} */ (options))
        });
      });

      layers[&#x27;grandcanyon&#x27;] &#x3D; new ol.layer.Tile({
        source: new ol.source.XYZ({
          url: &#x27;https://tileserver.maptiler.com/grandcanyon@2x/{z}/{x}/{y}.png&#x27;,
          crossOrigin: &#x27;&#x27;,
          tilePixelRatio: 2,
          maxZoom: 15,
          attributions: &#x27;Tiles © USGS, rendered with &#x27; +
            &#x27;&lt;a href&#x3D;&quot;http://www.maptiler.com/&quot;&gt;MapTiler&lt;/a&gt;&#x27;
        })
      });

      var startResolution &#x3D;
          ol.extent.getWidth(ol.proj.get(&#x27;EPSG:3857&#x27;).getExtent()) / 256;
      var resolutions &#x3D; new Array(22);
      for (var i &#x3D; 0, ii &#x3D; resolutions.length; i &lt; ii; ++i) {
        resolutions[i] &#x3D; startResolution / Math.pow(2, i);
      }

      layers[&#x27;states&#x27;] &#x3D; new ol.layer.Tile({
        source: new ol.source.TileWMS({
          url: &#x27;https://ahocevar.com/geoserver/wms&#x27;,
          crossOrigin: &#x27;&#x27;,
          params: {&#x27;LAYERS&#x27;: &#x27;topp:states&#x27;},
          serverType: &#x27;geoserver&#x27;,
          tileGrid: new ol.tilegrid.TileGrid({
            extent: [-13884991, 2870341, -7455066, 6338219],
            resolutions: resolutions,
            tileSize: [512, 256]
          }),
          projection: &#x27;EPSG:3857&#x27;
        })
      });


      var map &#x3D; new ol.Map({
        layers: [
          layers[&#x27;osm&#x27;],
          layers[&#x27;bng&#x27;]
        ],
        target: &#x27;map&#x27;,
        view: new ol.View({
          projection: &#x27;EPSG:3857&#x27;,
          center: [0, 0],
          zoom: 2
        })
      });


      var baseLayerSelect &#x3D; document.getElementById(&#x27;base-layer&#x27;);
      var overlayLayerSelect &#x3D; document.getElementById(&#x27;overlay-layer&#x27;);
      var viewProjSelect &#x3D; document.getElementById(&#x27;view-projection&#x27;);
      var renderEdgesCheckbox &#x3D; document.getElementById(&#x27;render-edges&#x27;);
      var renderEdges &#x3D; false;

      function updateViewProjection() {
        var newProj &#x3D; ol.proj.get(viewProjSelect.value);
        var newProjExtent &#x3D; newProj.getExtent();
        var newView &#x3D; new ol.View({
          projection: newProj,
          center: ol.extent.getCenter(newProjExtent || [0, 0, 0, 0]),
          zoom: 0,
          extent: newProjExtent || undefined
        });
        map.setView(newView);

        // Example how to prevent double occurrence of map by limiting layer extent
        if (newProj &#x3D;&#x3D; ol.proj.get(&#x27;EPSG:3857&#x27;)) {
          layers[&#x27;bng&#x27;].setExtent([-1057216, 6405988, 404315, 8759696]);
        } else {
          layers[&#x27;bng&#x27;].setExtent(undefined);
        }
      }


      /**
       * Handle change event.
       */
      viewProjSelect.onchange &#x3D; function() {
        updateViewProjection();
      };

      updateViewProjection();

      var updateRenderEdgesOnLayer &#x3D; function(layer) {
        if (layer instanceof ol.layer.Tile) {
          var source &#x3D; layer.getSource();
          if (source instanceof ol.source.TileImage) {
            source.setRenderReprojectionEdges(renderEdges);
          }
        }
      };


      /**
       * Handle change event.
       */
      baseLayerSelect.onchange &#x3D; function() {
        var layer &#x3D; layers[baseLayerSelect.value];
        if (layer) {
          layer.setOpacity(1);
          updateRenderEdgesOnLayer(layer);
          map.getLayers().setAt(0, layer);
        }
      };


      /**
       * Handle change event.
       */
      overlayLayerSelect.onchange &#x3D; function() {
        var layer &#x3D; layers[overlayLayerSelect.value];
        if (layer) {
          layer.setOpacity(0.7);
          updateRenderEdgesOnLayer(layer);
          map.getLayers().setAt(1, layer);
        }
      };


      /**
       * Handle change event.
       */
      renderEdgesCheckbox.onchange &#x3D; function() {
        renderEdges &#x3D; renderEdgesCheckbox.checked;
        map.getLayers().forEach(function(layer) {
          updateRenderEdgesOnLayer(layer);
        });
      };
    &lt;/script&gt;
  &lt;/body&gt;
&lt;/html&gt;</code></pre>
      </div>
    </div>

    <script src="./resources/common.js"></script>
    <script src="./resources/prism/prism.min.js"></script>
    <script src="loader.js?id=reprojection"></script>
  </body>
  <script>
  var packageUrl = 'https://raw.githubusercontent.com/openlayers/openlayers.github.io/build/package.json';
  fetch(packageUrl).then(function(response) {
    return response.json();
  }).then(function(json) {
    var latestVersion = json.version;
    document.getElementById('latest-version').innerHTML = latestVersion;
    var url = window.location.href;
    var branchSearch = url.match(/\/([^\/]*)\/examples\//);
    var cookieText = 'dismissed=-' + latestVersion + '-';
    var dismissed = document.cookie.indexOf(cookieText) != -1;
    if (!dismissed && /^v[0-9\.]*$/.test(branchSearch[1]) && '4.6.5' != latestVersion) {
      var link = url.replace(branchSearch[0], '/latest/examples/');
      fetch(link, {method: 'head'}).then(function(response) {
        var a = document.getElementById('latest-link');
        a.href = response.status == 200 ? link : '../../latest/examples/';
      });
      var latestCheck = document.getElementById('latest-check');
      latestCheck.style.display = '';
      document.getElementById('latest-dismiss').onclick = function() {
        latestCheck.style.display = 'none';
        document.cookie = cookieText;
      }
    }
  });
  </script>
</html>
